﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;

namespace Ooaavee.Data.Model
{
    /// <summary>
    /// A read only collection of tables.
    /// </summary>
    public sealed class ReadOnlyTableCollection : ReadOnlyCollection<Table>, ITableFinder
    {
        internal ReadOnlyTableCollection(IList<Table> tables) : base(tables)
        {
        }

        /// <summary>
        /// Searches for the table with the specified name.
        /// </summary>
        /// <param name="name">The String containing the name of the table to get.</param>
        /// <returns>A Table object with the specified name, if found; otherwise a null.</returns>
        /// <exception cref="AmbiguousMatchException">More than one table is found with the specified name.</exception>
        public Table this[string name]
        {
            get { return TableCollection.FindByName(this, name); }
        }

        /// <summary>
        /// Searches for the table with the specified name.
        /// </summary>
        /// <param name="name">The String containing the name of the table to get.</param>
        /// <returns>A Table object with the specified name, if found; otherwise a null.</returns>
        /// <exception cref="AmbiguousMatchException">More than one table is found with the specified name.</exception>
        public Table Find(string name)
        {
            return TableCollection.FindByName(this, name);
        }
    }
}
